<div class="list-body">
  <form id="product-search-form">
  <div class="row">

        <div class="search-input">
            <input type="text" class="displayProductName" placeholder="输入产品名称" onblur="Trim(this,this.value)">
            <input type="hidden" name="name" id="productNameDisNone">
            <div style="display: none;">
              <input type="text" name="pageCurrent" value="1">
              <input type="text" name="pageSize" value="12">
            </div>
            <button type="button" onclick="product_submit_btn()" class="search-btn" data-icon="search"></button>
        </div>
      <a class="add-btn" onclick="dialog_product_add()"><i class="fa fa-plus-square-o"></i><span>添加产品</span></a>
  </div>
  <ul class="row product-list-content list-content">

  </ul>
    </form>
  <div id="pagination_product" style="text-align: center; display: none;"></div>

</div>

<script type="text/javascript">
$(function(){
    var productTotalNum ;
    pagination_callback(1,12,1);
    $("input").placeholder(); 

})

function product_submit_btn(){
    $('.displayProductName').val()!='输入产品名称' ? $('#productNameDisNone').val($('.displayProductName').val()) : $('#productNameDisNone').val('');
    BJUI.ajax('ajaxform', {
        url: '/product/getproductlist',
        form: $.CurrentNavtab.find('#product-search-form'),
        validate: false,
        loadingmask: true,
        okCallback: function(json, options) {
          $('#pagination_product').pagination('destroy')
          $('#pagination_product').pagination({
              total:json.totalRow, pageSize:12, callback:pagination_callback
          })
        productTotalNum=json.totalRow;
          set_list(json);
          if(json.totalRow<=12){
              $("#pagination_product").css("display","none");
            }else{
              $("#pagination_product").css("display","block");
          }
        }
    })
  }

function pagination_callback(pageCurrent, pageSize,num) {
    var name=$("#productNameDisNone").val();
      BJUI.ajax('doajax', {
          url: '/product/getproductlist',
          okalert:false,
          data: {pageCurrent:pageCurrent, pageSize:pageSize,name:name},
          okCallback: function(json, options) {
             set_list(json);
              if(num==1){
                     $('#pagination_product').pagination({
                    total:json.totalRow, pageSize:12, callback:pagination_callback
                }) 
                  }
                   productTotalNum=json.totalRow;
                  if(json.totalRow>pageSize){
                    $("#pagination_product").css("display","block");
                  }else{
                    $("#pagination_product").css("display","none");
                  }
            }
       })
   }
 
function set_list(json){
   $('.product-list-content').empty();
    var btnArr=[
        {title:"编辑",icon:"fa fa-edit",fun:"product_editPage"},
        {title:"详情",icon:"fa fa-list-alt",fun:"product_detailPage"},
        {title:"删除",icon:"fa fa-trash-o",fun:"product_del"},
      ];
    $('.product-list-content').setList(json.list,btnArr,'iconfont icon-speaker-wireless');
}

function dialog_product_add(){
  BJUI.dialog({
    id:"productAdd",
    url:"/product/editPage",
    title:"添加产品",
        type:"post",
    width:"620",
    height:"600",
    mask:true,
    maxable:false
  })
}

function product_editPage(obj){
    var id=$(obj).parent().parent().prevAll("#item-id").text();
    BJUI.dialog({
      id:"productEdit",
      url:"/product/editPage",
      title:"编辑产品",
      type:"post",
      data:{"id":id},
      width:"620",
      height:"600",
      mask:true,
      maxable:false
    })
  }       
function product_del(obj){
  var id=$(obj).parent().parent().prevAll("#item-id").text();
  BJUI.alertmsg('confirm', '确定要删除吗！', {
      okCall: function() {
          BJUI.ajax('doajax', {
            url: '/product/del',
            type:"post",
            data:{"id":id},
            loadingmask: true,
            okCallback: function(json, options) {
                productTotalNum -=1;
                $('#pagination_product').pagination('destroy')
                $('#pagination_product').pagination({
            total:productTotalNum, pageSize:12, callback:pagination_callback
        });
               pagination_callback(1,12,1);
            }
          })
      }
  })
}

function product_detailPage(obj){  //查看私有协议字典详情
    var id=$(obj).parent().parent().prevAll("#item-id").text();
    
    BJUI.dialog({
         id:"productDetail",
         url:"/product/detail",
         title:"产品",
         type:"post",
         data:{"id":id},
         width:"620",
         height:"600",
         mask:true,
         maxable:false
        }) 
        
}
 
</script>

